Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
Combining two regex "^[\x20-\x7E]*$" and "\S(.*\S" into one

I have two regex that work separately: ^[\x20-\x7E]*$ and \S(.*\S

But I don't get how to combine the two so it will match them both.

I tried (^[\x20-\x7E]*$)*?(\S(.*\S)?) but it didn't work.

I used this in input tag with pattern="(^[\x20-\x7E]*$)*?(\S(.*\S)?)"

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Combine the two regexes with the pipe symbol. It is the same as the logical OR. Here's a code snippet demonstrating how to use this.

import re

regex_list = ["^[\x20-\x7E]$", "\S(.*\S)"]
regex = '|'.join(regex_list)

print(regex)                       # ^[ -~]$|\S(.*\S)
print(re.search(regex, "C"))       #matches first pattern
print(re.search(regex, "CAT CAT")) #matches second pattern
print(re.search(regex, " 3 "))     #matches neither pattern
about 4 years ago · Santiago Trujillo Relatório

0

One way to do this is to use word boundaries (\b) instead of the \S anchor:

^\b[\x20-\x7E]*\b$

This would match your given test case Priya@ #432, but would not match priya##23á or Priya@ #432 . You can see an example of this regex in action on Regex101 here.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda